﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Dynamic;using System.Text;
using System.Data.Linq;
using System.Transactions;
using LinqToSqlExtensions;using System.ServiceModel;
using System.Collections;
using System.Collections.Generic;
using CardsServer.DAL;

namespace CardsServer.WCF
{
	public partial interface IService
{
[OperationContract]
string maintianType_Add(maintianType model ,int ACID);


[OperationContract]
string maintianType_Update(maintianType model ,int ACID);


[OperationContract]
string maintianTypeBytid_Delete(int tid,int ACID);


[OperationContract]
maintianType maintianTypeBytid_Get(int tid,int ACID );


[OperationContract]
List<maintianType> maintianType_Get(string sortBy,int ACID);




}
public partial class Service : IService
{
#region  添加maintianType表数据
/// <summary>
/// 添加maintianType
/// </summary>
/// <param name="model">maintianType实体</param>
/// <returns>空或错误</returns>
public string maintianType_Add(maintianType model,int ACID)
{
if(model.tid==null )
{
return "『卡维护类别ID』不能为空！";
}
if(string.IsNullOrEmpty(model.title))
{
return "『维护类型名称』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.maintianType.Count(p=>p.tid==model.tid)>0)
{
return "主键已存在！";
}
if(ctx.maintianType.Count(p=>p.title==model.title)>0)
{
return "维护类型名称已存在！";
}
ctx.maintianType.InsertOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 添加失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  添加maintianType表数据事物用重构
/// <summary>
/// 添加maintianType事物用重构
/// </summary>
/// <param name="model">maintianType实体</param>
/// <returns>空或错误</returns>
private string maintianType_Add(maintianType model,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(model.tid==null )
{
return "『卡维护类别ID』不能为空！";
}
if(string.IsNullOrEmpty(model.title))
{
return "『维护类型名称』不能为空！";
}
if(ctx.maintianType.Count(p=>p.tid==model.tid)>0)
{
return "主键已存在！";
}
if(ctx.maintianType.Count(p=>p.title==model.title)>0)
{
return "维护类型名称已存在！";
}
ctx.maintianType.InsertOnSubmit(model);
return string.Empty;
}
#endregion



#region  修改maintianType表数据
/// <summary>
/// 修改maintianType
/// </summary>
/// <param name="model">maintianType实体</param>
/// <returns>空或错误</returns>
public string maintianType_Update(maintianType model,int ACID)
{
if(model.tid==null )
{
return "『卡维护类别ID』不能为空！";
}
if(string.IsNullOrEmpty(model.title))
{
return "『维护类型名称』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.maintianType.Count(p=>p.tid==model.tid)!= 1)
{
return "未找到指定记录或记录不唯一！";
}
maintianType maintianTypemodel=ctx.maintianType.Single(p => p.tid==model.tid);
if(model.tid!=null )
{
maintianTypemodel.tid=model.tid;
}
if(!string.IsNullOrEmpty(model.title))
{
maintianTypemodel.title=model.title;
}
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 修改失败!错误详细信息：" + ex.Message;
}
}
}
#endregion



#region  删除maintianType表Bytid数据
/// <summary>
/// 删除maintianTypeBytid
/// </summary>
/// <param name="tid">卡维护类别ID</param>
/// <returns>空或错误</returns>
public string maintianTypeBytid_Delete(int tid,int ACID)
{
if(tid==null )
{
return "『卡维护类别ID』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.maintianType.Count(p=>p.tid==tid)!=1)
{
return null;
}
maintianType model=ctx.maintianType.Single(p => p.tid== tid);
ctx.maintianType.DeleteOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 删除失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  删除maintianType表Bytid数据[事物用重构]
/// <summary>
/// 删除maintianTypeBytid[事物用重构]
/// </summary>
/// <param name="tid">卡维护类别ID</param>
/// <returns>空或错误</returns>
private string maintianTypeBytid_Delete(int tid,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(tid==null )
{
return "『卡维护类别ID』不能为空！";
}
if(ctx.maintianType.Count(p=>p.tid==tid)!=1)
{
return null;
}
maintianType model=ctx.maintianType.Single(p => p.tid== tid);
ctx.maintianType.DeleteOnSubmit(model);
return string.Empty;
}
#endregion



#region  获取maintianType表Bytid数据
/// <summary>
/// 获取maintianTypeBytid
/// </summary>
/// <param name="tid">卡维护类别ID</param>
/// <returns>当前表</returns>
public maintianType maintianTypeBytid_Get(int tid,int ACID)
{
if(tid==null )
{
return null;
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.maintianType.Count(p=>p.tid==tid)!=1)
{
return null;
}
return ctx.maintianType.SingleOrDefault(p=>p.tid==tid);
}
catch (Exception ex)
{
return null;
}
}
}
#endregion



#region  获取maintianType表数据
/// <summary>
/// 获取maintianType
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<maintianType></returns>
public List<maintianType> maintianType_Get(Expression<Func<maintianType, bool>> predicate , string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.maintianType.ToList();
}
 else 
{
return ctx.maintianType.OrderBy(sortBy).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.maintianType.Where(predicate).ToList();
}
 else 
{
return ctx.maintianType.Where(predicate).OrderBy(sortBy).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  获取maintianType表数据
/// <summary>
/// 获取maintianType
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<maintianType></returns>
public List<maintianType> maintianType_Get(string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
return maintianType_Get(null,sortBy, ACID);
}
catch (Exception)
{
return null;
}
}
}
#endregion


#region  获取maintianType表数据计数
/// <summary>
/// 获取maintianType表数据计数
/// </summary>
/// <returns>List<maintianType></returns>
public int maintianType_GetCount(Expression<Func<maintianType, bool>> predicate,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
return ctx.maintianType.Count();

}
 else
{
return ctx.maintianType.Where(predicate).Count();
}
}
catch 
{
return 0;
}
}
}
#endregion




#region  获取maintianType分页表数据
/// <summary>
/// 获取maintianType分页表数据
/// </summary>
/// <param name="pageIndex">当前页</param>
/// <param name="pageSize">页大小</param>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<maintianType></returns>
public List<maintianType> maintianType_Getpage(int pageIndex, int pageSize,Expression<Func<maintianType, bool>> predicate ,string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.maintianType.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.maintianType.OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.maintianType.Where(predicate).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.maintianType.Where(predicate).OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  批量修改maintianType表数据
/// <summary>
/// 批量修改maintianType
/// </summary>
/// <param name="predicate">Expression<Func<maintianType, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<maintianType,maintianType>> 更新表达式树</param>
/// <param name="returns">影响记录数</param>
public int maintianType_batchUpdate(Expression<Func<maintianType, bool>> predicate,Expression<Func<maintianType, maintianType>> updater,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.maintianType.Update(predicate, updater);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量修改maintianType表数据事物用重构
/// <summary>
/// 批量修改maintianType事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<maintianType, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<maintianType,maintianType>> 更新表达式树</param>
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int maintianType_batchUpdate(Expression<Func<maintianType, bool>> predicate,Expression<Func<maintianType, maintianType>> updater,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.maintianType.Update(predicate, updater);
return ok;
}
#endregion


#region  批量删除maintianType表数据
/// <summary>
/// 批量删除maintianType
/// </summary>
/// <param name="predicate">Expression<Func<maintianType, bool>></param> 查找表达式树
/// <param name="returns">影响记录数</param>
public int maintianType_batchDel(Expression<Func<maintianType, bool>> predicate,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.maintianType.Delete(predicate);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量删除maintianType表数据事物用重构
/// <summary>
/// 批量删除maintianType事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<maintianType, bool>></param> 查找表达式树
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int maintianType_batchDel(Expression<Func<maintianType, bool>> predicate,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.maintianType.Delete(predicate);
return ok;
}
#endregion


}
}

